package com.lhc.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author lhc
 * @Date 2021/8/2 9:04
 */
@RestController
@RequestMapping("/kafka")
public class KafkaController {

    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;


    // 发送消息
    @GetMapping("/send/{message}")
    public void sendMessage1(@PathVariable("message") String message) {
        System.out.println("发送消息");
        kafkaTemplate.send("test", message);
    }

}